package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.Praise;
import cn.wolfcode.trip.base.mapper.PraiseMapper;
import cn.wolfcode.trip.base.mapper.TravelMapper;
import cn.wolfcode.trip.base.service.IPraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class PraiseServiceImpl implements IPraiseService{

    @Autowired
    private TravelMapper travelMapper;
    @Autowired
    private PraiseMapper praiseMapper;

    public Integer getPraiseById(Long travelId, Long userId, int type) {
        return travelMapper.getPraiseById(travelId,userId,type);
    }

    public void save(Long travelId, Long userId, int type) {
        travelMapper.savePraise(travelId,userId,type);
    }

    public void delete(Long id, Long userId, int type) {
        travelMapper.daletePraise(id,userId,type);
    }

    @Override
    public List<Praise> getPraise(Long id, Integer type) {
        if (Praise.TYPE_TRAVEL.equals(type)) {
            return praiseMapper.getPraiseTravels(id);
        }else if (Praise.TYPE_STRATEGY_COMMENT.equals(type)){
            return praiseMapper.getPraiseStrategyComment(id);
        }else if (Praise.TYPE_FRIENDSHIP.equals(type)){
            return praiseMapper.getPraiseFriendships(id);
        }
        return null;
    }

    @Override
    public Map<String, Object> getPraiseNumbers(Long userId) {
        //查询游记/攻略点评/朋友圈点赞数量
        Integer travelsNum = praiseMapper.getPraiseTravelsNum(userId);
        Integer strategyCommentsNum = praiseMapper.getPraiseStrategyCommentsNum(userId);
        Integer friendshipsNum = praiseMapper.getPraiseFriendshipsNum(userId);
        //将数量对应封装
        Map<String, Object> map = new HashMap<>();
        map.put("travel", travelsNum);
        map.put("strategyComment", strategyCommentsNum);
        map.put("friendship", friendshipsNum);
        return map;
    }

    @Override
    public void updatePraiseState(Long praiseId) {
        praiseMapper.updatePraiseState(praiseId);
    }

    @Override
    public void updateFriendshipPraiseState(Long praiseId) {
        praiseMapper.updateFriendshipPraiseState(praiseId);
    }

    public Integer getPraiseNum(Long travelId, int type) {
        return travelMapper.getPraiseNum(travelId,type);
    }

    public List<Map> selectPraiseNum(Long[] travelId, int type) {
        return travelMapper.selectPraiseNum(travelId,type);
    }
}
